/*
 * Copyright (c) 2025 Industrial Software Feature Database
 */
package com.comac.ins.isfd.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import com.comac.ins.common.core.domain.R;
import com.comac.ins.common.core.validate.AddGroup;
import com.comac.ins.common.core.validate.EditGroup;
import com.comac.ins.common.idempotent.annotation.RepeatSubmit;
import com.comac.ins.common.log.annotation.Log;
import com.comac.ins.common.log.enums.BusinessType;
import com.comac.ins.common.web.core.BaseController;
import com.comac.ins.isfd.domain.bo.IsfdModelManagementCalculateFileBo;
import com.comac.ins.isfd.domain.vo.IsfdModelManagementCalculateFileDetailVo;
import com.comac.ins.isfd.service.IIsfdModelManagementCalculateFileService;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 模型管理-计算文件记录Controller
 *
 * @author Lion Li
 * @date 2024-08-19
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/isfd/modelManagementCalculateFile")
public class IsfdModelManagementCalculateFileController extends BaseController {

    @Autowired
    private IIsfdModelManagementCalculateFileService isfdModelManagementCalculateFileService;

    /**
     * 新增计算文件记录 包括 已选择的零组件、必备件、边界条件和载荷文件
     */
    @SaCheckPermission("isfd:modelManagementCalculateFile:add")
    @Log(title = "计算文件记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/save")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody IsfdModelManagementCalculateFileBo bo) {
        return toAjax(isfdModelManagementCalculateFileService.insertByBo(bo));
    }

    /**
     * 获取计算文件记录详细信息 包括 已选择的零组件、必备件、边界条件和载荷文件
     */
    @SaCheckPermission("isfd:modelManagementCalculateFile:query")
    @GetMapping("/queryById")
    public R<IsfdModelManagementCalculateFileDetailVo> getInfo(@NotNull(message = "主键不能为空")
                                                               @RequestParam("id") Long id) {
        return R.ok(isfdModelManagementCalculateFileService.queryDetailVoById(id));
    }

    /**
     * 修改计算文件记录 只能修改 必备件、边界条件和载荷文件
     */
    @SaCheckPermission("isfd:modelManagementCalculateFile:edit")
    @Log(title = "计算文件记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody IsfdModelManagementCalculateFileBo bo) {
        return toAjax(isfdModelManagementCalculateFileService.updateByBo(bo));
    }

    /**
     * 计算文件BDF下载
     */
    @SaCheckPermission("isfd:modelManagementCalculateFile:bdf:download")
    @Log(title = "计算文件BDF下载", businessType = BusinessType.EXPORT)
    @GetMapping("/bdf/partAndCalculateBdfDownload")
    public void partAndCalculateBdfDownload(@NotNull(message = "主键不能为空") @RequestParam("id") Long id, HttpServletResponse response) {
        isfdModelManagementCalculateFileService.partAndCalculateBdfDownload(id, response);
    }

}
